home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / NetFractal™ / Fractal 8 source / SenderSetup.cp < prev    next >
Encoding:
Text File  |  1995-06-24  |  3.4 KB  |  175 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CNetDemoApp.cp                ©1995 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Example program showing how to use UModalDialogs
  6.  
  7. #include "SenderSetup.h"
  8.  
  9. #include "OutPoint.h"
  10.  
  11. #include <URegistrar.h>
  12. #include <UReanimator.h>
  13.  
  14. #include <LEditField.h>
  15. #include <LTabGroup.h>
  16. #include <LCaption.h>
  17. #include <LRadioGroup.h>
  18. #include <LStdControl.h>
  19. #include <LDialogBox.h>
  20. #include <UModalDialogs.h>
  21. #include <PP_Messages.h>
  22.  
  23. #include "Fractal.h"
  24.  
  25. #pragma cplusplus on
  26.  
  27.  
  28.  
  29. #include <string.h>
  30.  
  31. const ResIDT    WIND_NewSession = 128;
  32. const PaneIDT    pTCPButton        = 1;
  33. const PaneIDT    pAtalkButton    = 2;
  34. const PaneIDT    pAddress        = 11;
  35.  
  36.  
  37. OutPoint* gOutPoint = nil;
  38.  
  39.  
  40.  
  41. void InitSender()
  42.  
  43. {
  44.     InitOpenTransport();    
  45.  
  46. /*
  47.     URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
  48.     URegistrar::RegisterClass(LEditField::class_ID, LEditField::CreateEditFieldStream);
  49.     URegistrar::RegisterClass(LTabGroup::class_ID, LTabGroup::CreateTabGroupStream);
  50.     URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
  51.     URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
  52.     URegistrar::RegisterClass(LStdRadioButton::class_ID, LStdRadioButton::CreateStdRadioButtonStream);
  53.     URegistrar::RegisterClass(LRadioGroup::class_ID, LRadioGroup::CreateRadioGroupStream);
  54.     URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
  55. */
  56. }
  57.  
  58. void CleanUpSender()
  59.  
  60. {
  61.     if (gOutPoint)
  62.         delete gOutPoint;
  63. }
  64.  
  65.  
  66.  
  67. void SpawnSender()
  68.  
  69. {
  70.  
  71.     if (gOutPoint)
  72.         return;
  73.  
  74.     DialogRef dia = GetNewDialog(999, nil, WindowRef (-1));
  75.     short xitem;
  76.     
  77.     do {
  78.         ModalDialog(nil, &xitem);
  79.     } while (xitem != 1);
  80.     
  81.     short itemType;
  82.     Handle itemH;
  83.     Rect box;
  84.     
  85.     GetDialogItem(dia, 2, &itemType, &itemH, &box);
  86.  
  87.  
  88.  
  89. /*
  90.     StDialogHandler dlog(WIND_NewSession, nil);
  91.     MessageT msg = 0;
  92.     
  93.     while (!msg)
  94.         msg = dlog.DoDialog();
  95.  
  96.     if (msg == msg_Cancel)
  97.         return;
  98. */
  99.  
  100.     Str255 address;
  101.     char configstr[80];
  102.     
  103.     GetDialogItemText(itemH, address);
  104.     DisposeDialog(dia);
  105.  
  106. /*
  107.     LEditField* adrStr = (LEditField*) dlog.GetDialog()->FindPaneByID(pAddress);
  108.     LStdRadioButton* tcpBut = (LStdRadioButton*) dlog.GetDialog()->FindPaneByID(pTCPButton);
  109. */    
  110.     if (1)
  111. //    if (tcpBut->GetValue())
  112.         strcpy(configstr, "udp");
  113.     else
  114.         strcpy(configstr, "ddp");
  115.     
  116. //    adrStr->GetDescriptor(address);
  117.     p2cstr(address);
  118.  
  119.  
  120.     // for now we just create a sender
  121.     
  122.     volatile OutPoint* point = nil;
  123.     
  124.     try {
  125.         point = new OutPoint(configstr, (char*) address, OUR_PORT);
  126.     }
  127.     catch(...) {
  128.         delete point;
  129.     }
  130.     gOutPoint = point;
  131.  
  132. }
  133.  
  134.  
  135. void
  136. BlastData()
  137. {
  138.     if (gOutPoint == nil)
  139.         return;
  140.  
  141.     DataDesc theData;
  142.  
  143.     PixMapHandle pmap = GetGWorldPixMap(gOffscreenGWorld);
  144.     char *baseAddr = GetPixBaseAddr(pmap);
  145.     long rowBytes = (*pmap)->rowBytes&0x3fff;
  146.  
  147. #define VV 100
  148. #define HH 165
  149. #define RB 256
  150. #define NR 4
  151.  
  152.     int v;
  153.     OTData    data[NR+1];
  154.     
  155.     data[0].fData = (UInt8*)&theData;
  156.     data[0].fLen  = 20;
  157.     data[0].fNext = &data[1];
  158.     for (v=VV; v<(VV+175); v+=NR) {
  159.         theData.rowBytes=RB;
  160.         theData.rowSize=RB;
  161.         theData.numRows=NR;
  162.         theData.xPos=0;
  163.         theData.yPos=v-VV;
  164.         int ix;
  165.         for (ix=0; ix<NR; ix++) {
  166.             data[ix+1].fData   = baseAddr+HH+rowBytes*(v+ix);
  167.             data[ix+1].fLen    = RB;
  168.             data[ix+1].fNext   = &data[ix+2];
  169.             // BlockMoveData(baseAddr+HH+rowBytes*(v+ix), &theData.data[ix*RB], RB);
  170.         }
  171.         data[NR].fNext = nil;
  172.         gOutPoint->SendData(&data, kNetbufDataIsOTData);
  173.     }
  174. }
  175.